/**
 * 上下文
 *
 */
define(["app", "comm/pager/PagerControl", "js/services/MessageBox", "js/services/MuseService", "js/filters/Moment"], function (app) {

    var deps = ["$scope", "$state", "$modal", "MessageBox", "MuseService", "$modalInstance", "selObj"];

    function controller ($scope, $state, $modal, MessageBox, MuseService, $modalInstance, selObj) {

        $scope.selObj = selObj;

        //初始化查询对象 和 分页对象
        $scope.queryObj = {
            "sort": "asc",
            "logId": selObj.id,
            "contextId": selObj.contextId
        };
        $scope.pagerObj = {
            //当前页号
            currentPage: 1,
            // 每页显示条数
            pageSize: 5,
            //总记录数
            totalCount: -1
        };

        //获取列表
        $scope.getObjList = function () {
            //封装查询条件
//        	if(selObj != undefined){
//        		$scope.queryObj.logId = selObj.id;
//            	$scope.queryObj.contextId = selObj.contextId;
//        	}
            $scope.pagerObj.searchMap = $scope.queryObj;
            MuseService.post("admin/messagelog/list.json", $scope.pagerObj).success(
                function (data, status, headers, config) {
                    if (data.state == 0) {
                        $scope.logList = data.data.itemList;
                        $scope.pagerObj.currentPage = data.data.currentPage;
                        //分页器
                        $scope.pagerObj = PageCtrl().page($scope.pagerObj, data.totalPage, $scope.pagerObj.currentPage);
                    }
                });
        };

        $scope.getObjList();

        $scope.pageChanged = function () {
            $scope.queryObj.logId = null;
            PageCtrl().check($scope.pagerObj);
            $scope.getObjList();
        };

        // 取消
        $scope.close = function () {
            $modalInstance.dismiss('cancel');
        };
    }

    controller.$inject = deps;
    app.lazy.controller("MessageLogModalController", controller);
});
